﻿//添加必要的动态连接库
using Model;
using System.Collections.Generic;
using DBUtility;


/**
 * 作者：陈杰
 * QQ  : 710782046
 * Email:ovenjackchain@gmail.com
 * Web :http://www.qidian10.com
 */
namespace DAO
{
    public class newsinfoDao
    {
        newsInfo _newsinfo = new newsInfo();
        /// <summary>
        /// 根据条件查找相应记录，并实现分页
        /// </summary>
        /// <param name="start">开始记录号</param>
        /// <param name="limit">分页大小</param>
        /// <param name="conditions">查找条件</param>
        /// <returns></returns>
        public IList<newsInfo> FindAllByPage_newsinfo(string start, string limit, string conditions)
        {
            return Common<newsInfo>.Dt2List(DbHelperSQL.FindByPage(_newsinfo, start, limit, conditions));
        }
        /// <summary>
        /// 查找符合条件记录的总条数，共分页使用
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="conditions"></param>
        /// <returns></returns>
        public string GetCount_newsinfo(string conditions)
        {
            return DbHelperSQL.GetCountByConditions(_newsinfo, conditions);
        }

        /// <summary>
        /// 根据类别查找出前6条记录，在首页桌面显示
        /// </summary>
        /// <param name="classify">类别</param>
        /// <returns></returns>
        public IList<newsInfo> FindNewsinfoByClassify(string classify)
        {
            return Common<newsInfo>.Dt2List(DbHelperSQL.Query("select top 8 * from newsInfo where newsclassify='" + classify + "'").Tables[0]);
        }

        /// <summary>
        /// 根据id查找相应的一条记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public newsInfo FindById_newsinfo(int id)
        {
            newsInfo model = new newsInfo();
            return Common<newsInfo>.Dt2Model(model,DbHelperSQL.FindByConditions(new newsInfo(), " newsid=" + id.ToString()));
        }

        /// <summary>
        /// 添加新纪录
        /// </summary>
        /// <param name="newsinfo">实体</param>
        /// <returns></returns>
        public bool Add_newsinfo(newsInfo newsinfo)
        {
            if (DbHelperSQL.Insert(newsinfo))
                return true;
            else
                return false;
        }

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="newsinfo">实体</param>
        /// <returns></returns>
        public bool Update_newsinfo(newsInfo newsinfo)
        {
            if (DbHelperSQL.Update(newsinfo))
                return true;
            else
                return false;
        }

        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="newsinfo">实体</param>
        /// <returns></returns>
        public bool Del_newsinfo(newsInfo newsinfo)
        {
            if (DbHelperSQL.Delete(newsinfo))
                return true;
            else
                return false;
        }
    }
}
